<?php

/**
 * Scribe文档中文化脚本
 * 在每次运行 scribe:generate 后执行此脚本来应用中文化
 */

$scribeViewPath = __DIR__ . '/../resources/views/scribe/index.blade.php';

if (!file_exists($scribeViewPath)) {
    echo "Scribe视图文件不存在: {$scribeViewPath}\n";
    exit(1);
}

$content = file_get_contents($scribeViewPath);

// 定义需要替换的文本映射
$translations = [
    // HTML属性
    'lang="en"' => 'lang="zh-CN"',

    // 页面标题（如果配置没有生效）
    'WP Lara Press API Documentation' => 'WP Lara Press API 接口文档',

    // 界面文本
    'Try it out ⚡' => '在线测试 ⚡',
    'Example request:' => '请求示例：',
    'Example response' => '响应示例',
    'Query Parameters' => '查询参数',
    'Body Parameters' => '请求体参数',
    'URL Parameters' => 'URL参数',
    'Headers' => '请求头',
    'Response Fields' => '响应字段',
    '<i>optional</i>' => '<i>可选</i>',
    '<i>required</i>' => '<i>必需</i>',

    // 状态文本
    'Loading...' => '加载中...',
    'Send Request' => '发送请求',
    'Send Request 💥' => '发送请求 💥',
    'data-initial-text="Send Request 💥"' => 'data-initial-text="发送请求 💥"',
    'Clear' => '清除',
    'Copy' => '复制',
    'Success' => '成功',
    'Error' => '错误',

    // HTTP方法说明
    'GET request' => 'GET 请求',
    'POST request' => 'POST 请求',
    'PUT request' => 'PUT 请求',
    'DELETE request' => 'DELETE 请求',
    'PATCH request' => 'PATCH 请求',
];

// 应用所有翻译
foreach ($translations as $english => $chinese) {
    $content = str_replace($english, $chinese, $content);
}

// 写回文件
file_put_contents($scribeViewPath, $content);

echo "✅ Scribe文档中文化完成！\n";
echo "📝 已处理的翻译项目: " . count($translations) . " 个\n";
echo "📄 文件路径: {$scribeViewPath}\n";
